﻿using System;
using System.Collections.ObjectModel;
using VisualWip.Core;
using VisualWip.TFS2010Common;

namespace VisualWip.TFS2010Providers
{
    public class WorkItemIdQuery : WorkItemQueryBase
    {
        public WorkItemIdQuery(TfsConnection connection) : base(connection)
        {
        }

        protected override Collection<WorkItem> RunGetWork()
        {
            try
            {
                var workItem =
                    WorkItemTransformer.TransformWorkItem(Connection,
                        Connection.WorkItemStore.GetWorkItem(int.Parse(QueryText)));
                return new Collection<WorkItem>() { workItem };
            }
            catch (Exception e)
            {
                return new Collection<WorkItem>() {new ErrorWorkItem(e)};
            }

        }

        protected override int RunGetWorkCount()
        {
            return RunGetWork().Count;
        }

        protected override void RefreshQueryTextIfEmpty()
        {
            //Do nothing
        }
    }
}